home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7349 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: cscsun3.larc.nasa.gov!hook
  2. From: hook@cscsun3.larc.nasa.gov (Ed Hook)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP: Illegal Pointer Arithmetic
  5. Date: 25 Feb 1996 20:59:22 GMT
  6. Organization: CSC/NASA Langley Research Center
  7. Distribution: world
  8. Message-ID: <4gqija$bmo@reznor.larc.nasa.gov>
  9. References: <4gj0ug$730@news.one.net> <danpop.825121139@rscernix> <31306a18.309961701@nntp.ix.netcom.com> <4gq77b$bmo@reznor.larc.nasa.gov>
  10. Reply-To: hook@cscsun3.larc.nasa.gov
  11. NNTP-Posting-Host: cscsun3.larc.nasa.gov
  12.  
  13.  Following up to myself:
  14.  
  15. In article <4gq77b$bmo@reznor.larc.nasa.gov>, hook@cscsun3.larc.nasa.gov (Ed Hook) writes:
  16. |> In article <31306a18.309961701@nntp.ix.netcom.com>, miker3@ix.netcom.com (Mike Rubenstein) writes:
  17.  
  18.        [ *deletia* ]
  19. |> |> 
  20. |> |> Not quite that, but Shildt's Annotated ANSI C Standard says
  21. |> |> 
  22. |> |>     The following fragment illustrates how files are commonly 
  23. |> |>     read:
  24. |> |> 
  25. |> |>         do {
  26. |> |>           ch = fgetc(fp);
  27. |> |>           /* ... */
  28. |> |>         } while (!feof(fp));
  29. |> |> 
  30. |> |> Come on Dan.  You're slipping.  Surely you could have guessed who
  31. |> |> teaches this idiocy.
  32. |> |>
  33. |>    It depresses me to have to defend Schildt, but that loop actually
  34. |>    works as advertised. (I *do* question his use of "commonly", since
  35. |>    I have encountered _any_ code that does it that way ... .) Anyhow,
  36. |>    since 'feof()' is called *after* each iteration of the loopbody,
  37. |>    the loop terminates precisely after the last character is fetched
  38. |>    from the file.
  39. |>
  40.   Blair Houghton gently pointed out to me (_via_ e-mail) that the above
  41.   defense of Schildt is *erroneous*, since the code in question fails on
  42.   an _empty_ input file. Overall, I feel somehow _cleaner_ now ...
  43.   
  44. |> |> 
  45. |> |> Michael M Rubenstein
  46. |> 
  47. |> -- 
  48. |>  Ed Hook                              |       Coppula eam, se non posit
  49. |>  Computer Sciences Corporation        |         acceptera jocularum.
  50. |>  NASA Langley Research Center         | Me? Speak for my employer?...<*snort*>
  51. |>  Internet: hook@cscsun3.larc.nasa.gov |        ... Get a _clue_ !!! ...
  52.  
  53. -- 
  54.  Ed Hook                              |       Coppula eam, se non posit
  55.  Computer Sciences Corporation        |         acceptera jocularum.
  56.  NASA Langley Research Center         | Me? Speak for my employer?...<*snort*>
  57.  Internet: hook@cscsun3.larc.nasa.gov |        ... Get a _clue_ !!! ...
  58.